package cn.youframe.sample.transaction;

import cn.youframe.frame.base.BaseCtrl;
import cn.youframe.frame.beans.AjaxVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * User: Administrator
 * DateTime: 12-7-23 下午10:13
 * Desc:
 */
@Controller
@RequestMapping(value = "/sample")
public class TransactionCtrl extends BaseCtrl {
    @Autowired
    TransactionService transactionService;
    @RequestMapping(value = "/TransactionCtrl!transactionTest.do")
    public @ResponseBody AjaxVo transactionTest(HttpServletRequest request){
        AjaxVo retMsg=new AjaxVo();
        try{
            String memo=request.getParameter("memo");
            int ret=transactionService.doMenu(memo);
            retMsg.setResObj(ret+",执行成功，事务提交成功！");
        }catch (Exception e){
            retMsg.setResObj("执行失败，事务回滚："+e.getMessage());
            logger.error(e.getMessage(),e);
        }
        return retMsg;
    }
    @RequestMapping(value = "/TransactionCtrl!getPKey.do")
    public @ResponseBody AjaxVo getPKey(HttpServletRequest request){
        AjaxVo retMsg=new AjaxVo();
        try{
            Object obj= transactionService.insertGetKey();
            retMsg.setResObj("Key:"+obj);
        }catch (Exception e){
            logger.error(e.getMessage(),e);
        }
        return retMsg;
    }
    @RequestMapping(value = "/TransactionCtrl!getPKeyOra.do")
    public @ResponseBody AjaxVo getPKeyOra(HttpServletRequest request){
        AjaxVo retMsg=new AjaxVo();
        Object keys=null;
        try{
            keys=transactionService.insertGetKeyOra();
        }catch (Exception e){
            logger.error(e.getMessage(),e);
        }
        retMsg.setResObj(keys);
        return retMsg;
    }
}
